package com.sun.umbrella.controller.oauth;

import com.sun.core.web.result.Result;
import com.sun.umbrella.domain.bo.OauthClientBO;
import com.sun.umbrella.service.oauth2.ClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Jay
 * @version v1.0
 * @description 授权配置相关的接口
 * @date 2018-06-01 10:39
 */
@Controller
@Slf4j
@RequestMapping("/pc/oauth2")
public class OauthController {


    @Autowired
    private ClientService clientService;


    /**
     * 查询授权客户端列表
     *
     * @return
     */
    @RequestMapping("/queryClientList")
    @ResponseBody
    public Result<List<OauthClientBO>> queryClientList() {
        // 查询
        return Result.wrapSuccessfulResult(clientService.queryClientList());
    }


    /**
     * 客户端启用或禁用
     *
     * @param clientId
     * @param enable
     * @return
     */
    @RequestMapping("/enableClient")
    @ResponseBody
    public Result<Boolean> enableClient(String clientId, Integer enable) {
        // 查询
        return Result.wrapSuccessfulResult(clientService.enableClient(clientId, enable));
    }


    /**
     * 创建新的客户端
     *
     * @param clientName
     * @return
     */
    @RequestMapping("/createClient")
    @ResponseBody
    public Result<Boolean> createClient(String clientName) {
        // 查询
        return Result.wrapSuccessfulResult(clientService.createClient(clientName));
    }

    /**
     * 移除客户端
     *
     * @param clientId
     * @return
     */
    @RequestMapping("/deleteClient")
    @ResponseBody
    public Result<Boolean> deleteClient(String clientId) {
        // 删除
        clientService.deleteClient(clientId);
        return Result.wrapSuccessfulResult(Boolean.TRUE);
    }

}
